using Admin2025.Domain.Entities.App;

namespace Admin2025.Domain.DomainService;
// RBAC领域服务，封装权限相关的业务逻辑
public class RbacDomainService
{
// 判断用户是否对某资源有某操作权限
public bool UserHasResourcePermission(AppUser user , string resourcePath, string permissionCode)
{
    // 遍历用户的所有角色，判断是否有某个角色拥有指定权限且该权限包含指定资源
    return user.Roles.Any(role =>
            role.Permissions.Any(permission =>
                permission.Code == permissionCode &&
                permission.Resources.Any(resource => resource.Path == resourcePath)
            )
        );
}
}